home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FOPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  501 b   |  21 lines

  1. /* fopen.c */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     unsigned char buffer[81];
  7.             /* Open the file. Note that we need two '\' because
  8.              * backslash denotes the beginning of a C escape
  9.              * sequence. */
  10.     if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
  11.     {
  12.         printf("fopen failed.\n");
  13.         exit(0);
  14.     }
  15.     printf("Contents of c:autoexec.bat:\n");
  16.     while (fgets(buffer, 80, infile) != NULL)
  17.     {
  18.         printf(buffer);
  19.     }
  20.     fclose(infile); /* Close file before exiting */
  21. }